<?php 
namespace app\admin\controller;
class Model extends Common {

	public function index(){
		$models = \Ebcms::db() -> select('model', '*');
		$this -> assign('models', $models);
		return $this -> html($this -> fetch());
	}

	public function add(){
		if (\Ebcms::isPost()) {
			\Ebcms::db() -> insert('model', [
				'title'=>\mylib\Input::post('title'),
			]);
			return $this -> success('操作成功！', \mylib\Route::buildUrl('/admin/model/index'));
		}else{
			return $this -> html($this -> fetch());
		}
	}

	public function edit(){
		if (\Ebcms::isPost()) {
			\Ebcms::db() -> update('model', [
				'title'=>\mylib\Input::post('title'),
			], [
				'id'=>\mylib\Input::post('id')
			]);
			return $this -> success('操作成功！', \mylib\Route::buildUrl('/admin/model/index'));
		}else{
			$model = \Ebcms::db() -> get('model', '*', ['id'=>\mylib\Input::get('id')]);
			$this -> assign('model', $model);
			return $this -> html($this -> fetch());
		}
	}

	public function del(){
		if (\Ebcms::isAjax()) {
			\Ebcms::db() -> delete('field', [
				'model_id' => \mylib\Input::post('id')
			]);
			\Ebcms::db() -> delete('model', [
				'id'=>\mylib\Input::post('id'),
			]);
			return $this -> success('操作成功！');
		}
	}
}